package com.vincent.template.store;

import com.alicp.jetcache.Cache;
import com.alicp.jetcache.anno.Cached;
import com.alicp.jetcache.anno.CreateCache;
import com.vincent.template.commons.base.VctTriple;
import com.vincent.template.service.security.AuthUriService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.Set;


/**
 * @author Vincent Wang
 * @date 2021/1/15 20:10
 */
@Component
public class AuthUriStore {

    @Autowired
    private AuthUriService authUriService;

    @CreateCache(name = "system:uri:")
    private Cache<String, List<VctTriple<Long, String, String>>> uriCache;
    @CreateCache(name = "system:authuribinding:")
    private Cache<String, Map<String, Set<Long>>> aubCache;

    @Cached(name = "system:uri:", key = "'all'")
    public List<VctTriple<Long, String, String>> findUris() {
        return authUriService.findUris();
    }

    public void refreshUris() {
        uriCache.put("all", authUriService.findUris());
    }

    @Cached(name = "system:authuribinding:", key = "'all'")
    public Map<String, Set<Long>> findAuthUrisMap() {
        return authUriService.findAuthUrisMap();
    }

    public void refreshAuthUrisMap() {
        aubCache.put("all", authUriService.findAuthUrisMap());
    }
}
